package com.cswnode.demo.entity;

/**
 * 分页查询
 */
public class Page {
    /**
     *当前页面
     */
    private int current = 1;
    /**
     *限制的条数
     */
    private int limit = 10;
    /**
     *总条数
     */
    private int rows;

    /**
     * 分页查询起始位置
     */
    private int offset;
    /**
     *总页数
     */
    private int total;
    /**
     *起始页
     */
    private int start;
    /**
     *结束页
     */
    private int end;



    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        if (current >= 1 ){
            this.current = current;
        }
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        if (limit >=1 && limit <= 100){
            this.limit = limit;
        }
    }
    public int getOffset() {
        return (current - 1) * limit;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getTotal() {
        if (rows % limit == 0){
            return rows / limit;
        }else {
            return rows / limit + 1;
        }
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getStart() {
        int start = current - 2;
        return start < 1 ? 1 : start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        int end = current + 2;
        int total = getTotal();
        return end < total ? end : total;
    }

    public void setEnd(int end) {
        this.end = end;
    }
}
